
package com.example.xinlijiankangsys.controller;

import com.example.xinlijiankangsys.service.UserInfoService;
import io.micrometer.common.util.StringUtils;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/api/userInfo")
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;
    @GetMapping("/search")
    public ResponseEntity<List<Map<String, Object>>> searchUsers(
            @RequestParam String keyword
    ) {

        // 1. 参数校验
        if (StringUtils.isBlank(keyword)) {
            return ResponseEntity.ok(Collections.emptyList());
        }
        // 2. 获取并返回标准格式数据
        List<Map<String, Object>> result = userInfoService.searchUsers(keyword);
        return ResponseEntity.ok(result);
    }

    @GetMapping("/api/userInfo")
    public String getUserInfo(@Param("userId") String userId){
        System.out.println(userId);
        return userId;
    }

}
